package com.zxstudio.mybatis.generator.startup;

import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.internal.DefaultShellCallback;

import java.util.ArrayList;
import java.util.List;

public class GeneratorApplication {

    public static void main(String[] args) {
        try {
            // 注意windows下， 如果targetProject输出目录要加上工程名， targetProject="mybatis-generator\output"，通过MAVEN PLUGIN生成不用加工程名
            List<String> warnings = new ArrayList<String>();
            boolean overwrite = true;
            ConfigurationParser cp = new ConfigurationParser(warnings);
            Configuration config = cp.parseConfiguration(GeneratorApplication.class.getClassLoader().getResourceAsStream("generatorConfig.xml"));
            DefaultShellCallback callback = new DefaultShellCallback(overwrite);
            MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
            myBatisGenerator.generate(null);
            if(warnings.size() >0 ) {
                System.out.println("Warnning Msg :");
                for(String warn : warnings) {
                    System.out.println(warn);
                }
            }

        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}